package cn.imnaer.rest.controller;

import java.util.List;

import javax.jws.WebService;

import cn.imnaer.common.factory.JacksonUtil;
import cn.imnaer.service.persistence.model.Scenic;
import cn.imnaer.service.persistence.model.ScenicContribution;
import cn.imnaer.service.rest.resquest.model.ScenicContributeParams;
import cn.imnaer.service.rest.scenic.ScenicComponentRestApi;
import cn.imnaer.service.rest.view.model.PageInfo;
import cn.imnaer.service.rest.view.model.ScenicContributionView;
import cn.imnaer.service.rest.view.model.ScenicDetailView;
import cn.imnaer.service.rest.view.model.SimpleResponse;
import cn.imnaer.service.rpc.collect.application.CollectComponentRpcApiImpl;
import cn.imnaer.service.rpc.scenic.impl.ScenicComponentRpcApiImpl;

@WebService
public class ScenicComponentController implements ScenicComponentRestApi {
	private ScenicComponentRpcApiImpl  scenicComponent=new ScenicComponentRpcApiImpl();

	@Override
	public String publishContribute(String contributeJson) {
   ScenicContributeParams params = JacksonUtil.jsonToBean(contributeJson,ScenicContributeParams.class);
        ScenicContribution contribution = params.toScenicContribution();
	    contribution=	this.scenicComponent.publishContribution(contribution);
	    ScenicContributionView view=ScenicContributionView.valueOf(contribution);
		return new SimpleResponse().success(view);
	}

	@Override
	public String getScenicDatail(String scenicId,String userId) {	
	Scenic scenic = this.scenicComponent.getScenicById(scenicId);
	ScenicDetailView  detailView=ScenicDetailView.valueOf(scenic);
    List<ScenicContribution> contributions = this.scenicComponent.getScenicContributionList(scenicId);
		List<ScenicContributionView> scViews = ScenicContributionView.valueOfList(contributions);
		detailView.setContributionViews(scViews);
		List<String> scenicIds = new CollectComponentRpcApiImpl().getMyCollectScenicList(userId);
		if(scenicIds.contains(detailView.getScenicId())){
			detailView.setIsCollect(true);
		}	
		/**
		 * userId 与名字设定为死
		 */
		detailView.setContributeUserId("10000");
		detailView.setContributeUserName("near君");
		return new SimpleResponse().success(detailView);
	}

	@Override
	public String search(String keyword, String userId, int page) {
	
		return null;
	}

	


}
